home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8106 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: ssc.sas.upenn.edu!modavis
  2. From: modavis@ssc.sas.upenn.edu (Morris A. Davis)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Borland Addition
  5. Date: 14 Feb 1996 18:29:25 GMT
  6. Organization: University of Pennsylvania
  7. Message-ID: <4ft9m5$fsr@netnews.upenn.edu>
  8. References: <2d7cc$14c35.82@NEWS>
  9. NNTP-Posting-Host: ssc.sas.upenn.edu
  10. X-Newsreader: TIN [version 1.2 PL2-upenn1.3]
  11.  
  12. Gooseman () wrote:
  13. : I just saw an interesting bug in "Windows Developer" magazine (I think
  14. : that's the title).
  15.  
  16. : #include <iostream.h>
  17. : int main()
  18. : {
  19. :   int i = 1;
  20. :   int j = 1;
  21.  
  22. :   if(i)
  23. :     i = i + 4;
  24. :     else
  25. :     i = j + 4;
  26.  
  27. :   cout << i;
  28. : }
  29.  
  30. : You would expect the output to be 5, but the result will be 9!  I
  31. : tried this under 4.52 and 4.0 and both produced the same results.
  32.  
  33. First, I set the target to  Easy Win...
  34. I tried this in my Borland 4.52, and I got the same result (9).  When I
  35. changed the line
  36.     i=i+4;
  37. to
  38.     i+=4;
  39. I got the correct result, 5
  40.  
  41. However, if you change the target to Win32 (and remember to add return
  42. 0; at the end of the program), with the i=i+4; line (as well as with the
  43. i+=4; line), you get the correct result (5).  This was with the
  44. "Console" option of Win32.
  45.  
  46. Curious.
  47.  
  48. Morris Davis
  49.